import { stringify } from 'qs';
import request from '../utils/request';

export async function queryProjectNotice() {
  return request('/api/project/notice');
}

export async function queryActivities() {
  return request('/api/activities');
}

export async function queryAidTask(params) {
  return request(`/back_end/aidTask/all?${stringify(params)}`);
}

export async function removeAidTask(params) {
  return request('/back_end/aidTask/remove', {
    method: 'POST',
    body: {
      ...params,
      // method: 'delete',
    },
  });
}

export async function addAidTask(params) {
  return request('/back_end/aidTask/save', {
    method: 'POST',
    body: {
      ...params,
      // method: 'post',
    },
  });
}

export async function queryAid(params) {
  return request(`/back_end/aid/all?${stringify(params)}`);
}

export async function removeAid(params) {
  return request('/back_end/aid/remove', {
    method: 'POST',
    body: {
      ...params,
      // method: 'delete',
    },
  });
}

export async function addAid(params) {
  return request('/back_end/aid/save', {
    method: 'POST',
    body: {
      ...params,
      // method: 'post',
    },
  });
}

export async function queryPayment(params) {
  return request(`/back_end/payment/all?${stringify(params)}`);
}

export async function addPayment(params) {
  return request('/back_end/payment/add', {
    method: 'POST',
    body: {
      ...params,
      // method: 'post',
    },
  });
}

// export async function queryOrderName(params) {
//   return request(`/back_end/order/name/all?${stringify(params)}`);
// }

async function sleep(time) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, time);
  });
}

export async function queryAdvertiser(params) {
  await sleep(100);
  return request(`/back_end/ader/all?${stringify(params)}`);
}

// export async function queryAderName(params) {
//   return request(`/back_end/ader/name/all?${stringify(params)}`);
// }

export async function removeAdvertiser(params) {
  return request('/back_end/ader/remove', {
    method: 'POST',
    body: params.id,
  });
}

export async function addAdvertiser(params) {
  return request('/back_end/ader/save', {
    method: 'POST',
    body: {
      ...params,
      // method: 'post',
    },
  });
}

export async function queryAd(params) {
  return request(`/back_end/ad/all?${stringify(params)}`);
}

export async function queryAdEnums() {
  return request('/back_end/ad/enums');
}

export async function removeAd(params) {
  return request('/back_end/ad/remove', {
    method: 'POST',
    body: {
      ...params,
      // method: 'delete',
    },
  });
}

export async function addAd(params) {
  return request('/back_end/ad/save', {
    method: 'POST',
    body: {
      ...params,
      // method: 'post',
    },
  });
}

export async function queryOrder(params) {
  return request(`/back_end/order/all?${stringify(params)}`);
}

export async function queryAdReport(params) {
  return request(`/back_end/adReport/all/byName?${stringify(params)}`);
}

export async function queryAdReport4Date(params) {
  return request(`/back_end/adReport/all/byDate?${stringify(params)}`);
}

export async function changeStatus(params) {
  return request(`/back_end/order/change?${stringify(params)}`);
}

export async function changeAdStatus(params) {
  return request(`/back_end/ad/change?${stringify(params)}`);
}

export async function queryOrderEnums() {
  return request('/back_end/order/enums');
}

export async function queryAidEnums() {
  return request('/back_end/aid/enums');
}

export async function removeOrder(params) {
  return request('/back_end/order/remove', {
    method: 'POST',
    body: {
      ...params,
      // method: 'delete',
    },
  });
}

export async function addOrder(params) {
  return request('/back_end/order/save', {
    method: 'POST',
    body: {
      ...params,
      // method: 'post',
    },
  });
}


export async function queryRule(params) {
  return request(`/api/rule?${stringify(params)}`);
}

export async function removeRule(params) {
  return request('/api/rule', {
    method: 'POST',
    body: {
      ...params,
      method: 'delete',
    },
  });
}

export async function addRule(params) {
  return request('/api/rule', {
    method: 'POST',
    body: {
      ...params,
      // method: 'post',
    },
  });
}

export async function fakeSubmitForm(params) {
  return request('/api/forms', {
    method: 'POST',
    body: params,
  });
}

export async function fakeChartData() {
  return request('/api/fake_chart_data');
}

export async function queryTags() {
  return request('/api/tags');
}

export async function queryBasicProfile() {
  return request('/api/profile/basic');
}

export async function queryAdvancedProfile() {
  return request('/api/profile/advanced');
}

export async function queryFakeList(params) {
  return request(`/api/fake_list?${stringify(params)}`);
}

export async function fakeAccountLogin(params) {
  return request('/back_end/login/account', {
    method: 'POST',
    body: params,
  });
}

export async function fakeRegister(params) {
  return request('/api/register', {
    method: 'POST',
    body: params,
  });
}

export async function queryNotices() {
  return request('/api/notices');
}
